package com.mida.dms.knw.controller;


import com.mida.dms.knw.entity.KnwConceptualDomain;
import com.mida.dms.knw.entity.KnwSlot;
import com.mida.dms.knw.entity.vo.KnwSlotVo;
import com.mida.dms.knw.entity.vo.MapperPage;
import com.mida.dms.knw.service.KnwSlotService;
import com.mida.dms.knw.util.exception.DtException;
import com.mida.dms.knw.vo.KnwSlotPageVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 本体slot维护
 * @author lzq
 *
 */
@RestController
@RequestMapping("/knwNoumenon")
@Api(tags = "本体slot维护")
@CrossOrigin
@Slf4j
public class KnwSlotController {

    @Autowired
    KnwSlotService knwSlotService;

    @ApiModelProperty(value = "更新slot对应编码体系(发布状态)",notes = "更新slot对应编码体系(发布状态)")
    @GetMapping(value = "/updateDetailCoding",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult updateDetailCoding(@RequestParam(value = "slotSoid")Long slotSoid,
                                           @RequestParam(value = "detailCodingSystemSoid",required = false)Long detailCodingSystemSoid){

        return knwSlotService.updateDetailCoding(slotSoid,detailCodingSystemSoid);
    }

    @ApiOperation(value = "发布本体",notes = "发布本体")
    @PostMapping(value = "/publish",consumes = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult publish(@RequestParam(value = "noumenonSoid") Long noumenonSoid,
                                @RequestBody List<KnwSlot> list){

        return knwSlotService.publish(noumenonSoid,list);
    }

    /**
     *新增slot(本体是草稿状态)
     */
    @ApiOperation(value = "新增slot", notes = "新增slot")
    @PostMapping(value = "/addSlot",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ActionResult add(@RequestBody KnwSlotVo vo) {

        return knwSlotService.add(vo);
    }

    /**
     *  分页查询
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping(value = "/selectSlot",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<PageResultVo<KnwSlotVo>> findPage(@RequestBody KnwSlotPageVo vo) {
        return knwSlotService.find(vo);
    }

    /**
     *  根据本体soid查询所有本体Slot
     */
    @ApiOperation(value = "查询所有本体Slot", notes = "查询所有本体Slot")
    @GetMapping(value = "/findAllSlot")
    @ResponseBody
    public ListResult<List<KnwSlotVo>> findAllSoltBynoumenonSoid(@RequestParam Long noumenonSoid) {
        return knwSlotService.findAllSoltBynoumenonSoid(noumenonSoid);
    }

    @ApiOperation(value = "根据slotsoid查询一条slot信息",notes = "根据slotsoid查询一条slot信息")
    @GetMapping(value = "/selectSlotBySoid",produces = {"application/json;charset=UTF-8"})
    public ListResult<KnwSlotVo> findBySlotSoid(@RequestParam Long soid){
        return knwSlotService.findBySoid(soid);
    }

    /**
     *slot排序
     */
    @ApiOperation(value = "slot排序", notes = "slot排序")
    @PutMapping(value = "/orderSlot",produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ActionResult order(@RequestParam("originalSlotOrder") Long originalSlotOrder,
                              @RequestParam("newSlotOrder") Long newSlotOrder,
                              @RequestParam("slotSoid") Long slotSoid) throws DtException {
        return knwSlotService.order(originalSlotOrder,newSlotOrder,slotSoid);
    }

    /**
     *更新slot
     */
    @ApiOperation(value = "更新slot", notes = "更新slot")
    @PostMapping(value = "/updateSlot",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<Object> update(@RequestBody KnwSlotVo vo) throws DtException {
        return knwSlotService.update(vo);
    }

    /**
     *删除slot
     */
    @ApiOperation(value = "删除slot", notes = "删除slot")
    @PostMapping(value = "/deleteSlot",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ActionResult delete(@RequestBody KnwSlotVo vo) throws Exception {
        return knwSlotService.delete(vo);
    }

    /**
     *Slot简码查询
     */
    @ApiOperation(value = "Slot简码查询", notes = "Slot简码查询")
    @PostMapping(value = "/selectSlotNameByCode",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<Object> selectSlotNameByCode(@RequestBody MapperPage vo) {
        return knwSlotService.selectSlotNameByCode(vo);
    }

    /**
     * 选中Slot名称后加载定义域
     */
    @ApiOperation(value = "选中Slot名称后加载定义域", notes = "选中Slot名称后加载定义域")
    @PostMapping(value = "/getDataBySlotName",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<Object> getDataBySlotName(@RequestBody KnwSlotVo vo){
        return knwSlotService.getDataBySlotName(vo);
    }

    /**
     * 根据定义域id获取编码体系
     */
    @ApiOperation(value = "根据定义域id获取编码体系", notes = "根据定义域id获取编码体系")
    @PostMapping(value = "/getDataByDomainId",consumes = { "application/json;charset=UTF-8" })
    @ResponseBody
    public ListResult<Object> getDataByDomainId(@RequestBody KnwConceptualDomain domain){
        return knwSlotService.getDataByDomainId(domain);
    }
}
